//
//  TextRecursionView.m
//  DingDongXiChe
//
//  Created by wtjr on 2017/11/28.
//  Copyright © 2017年 xieyingze. All rights reserved.
//

#import "CustomReuseCellView.h"

@interface CustomReuseCellView()

@property (nonatomic, strong) BaseImageView *iconImageView;
@property (nonatomic, strong) BaseLabel *titleLabel;

@property (nonatomic, strong) BaseLabel *valueLabel;

@property (nonatomic, strong) BaseImageView *arrowImageView;

@property (nonatomic, strong) UIView *line;

@end

@implementation CustomReuseCellView


#pragma mark - BaseMethod

- (void)initData {
    _cellType = kCustomCellTypeText;
}

- (void)initSubViews {
    [self addSubview:self.iconImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.line];
    //
    [self addSubview:self.valueLabel];
    //
    [self addSubview:self.inputTextfiled];
    //
    [self addSubview:self.arrowImageView];
    [self addSubview:self.selectButton];
}

- (void)autoLayoutSubViews {
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(kUI_MarginW));
        make.centerY.equalTo(@0);
        make.height.width.equalTo(@16);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.mas_right).offset(10);
        make.centerY.equalTo(@0);
        make.height.equalTo(@20);
    }];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView);
        make.right.bottom.equalTo(@0);
        make.height.equalTo(@0.5);
    }];
    [self.valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kUI_MarginW));
        make.centerY.equalTo(@0);
        make.height.equalTo(@20);
    }];
    [self.inputTextfiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kUI_MarginW));
        make.centerY.equalTo(@0);
        make.height.equalTo(@20);
        make.width.equalTo(@(120 * kUI_Percent));
    }];
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-kUI_MarginW));
        make.centerY.equalTo(@0);
        make.height.equalTo(@12);
        make.width.equalTo(@8);
    }];
    [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.arrowImageView.mas_left).offset(-5);
        make.centerY.equalTo(@0);
        make.width.equalTo(@(160 * kUI_Percent));
        make.height.equalTo(@20);
    }];
    
    self.inputTextfiled.hidden = YES;
    self.arrowImageView.hidden = self.selectButton.hidden = YES;
}

#pragma mark - Interface


#pragma mark - Delegate


#pragma mark - TouchEvent


#pragma mark - Setter

- (void)setTitle:(NSString *)title {
    self.titleLabel.text = [NSString stringWithFormat:@"%@:",title];
}

- (void)setIconName:(NSString *)iconName {
    self.iconImageView.image = [UIImage imageNamed:iconName];
}

- (void)setValue:(NSString *)value {
    self.valueLabel.text = value;
}

- (void)setClickTitle:(NSString *)clickTitle {
    self.selectButton.title = clickTitle;
}

- (void)setShowLine:(BOOL)showLine {
    self.line.hidden = !showLine;
}

- (void)setCellType:(kCustomCellType)cellType {
    switch (cellType) {
        case kCustomCellTypeText: {
            self.valueLabel.hidden = NO;
            self.inputTextfiled.hidden = YES;
            self.arrowImageView.hidden = self.selectButton.hidden = YES;
        }
            break;
        case kCustomCellTypeInput: {
            self.valueLabel.hidden = YES;
            self.inputTextfiled.hidden = NO;
            self.arrowImageView.hidden = self.selectButton.hidden = YES;
        }
            break;
        case kCustomCellTypeClick: {
            self.valueLabel.hidden = YES;
            self.inputTextfiled.hidden = YES;
            self.arrowImageView.hidden = self.selectButton.hidden = NO;
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - Getter

- (BaseImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [BaseImageView new];
    }
    return _iconImageView;
}

- (BaseLabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [BaseLabel new];
        [_titleLabel setLabelStyle:@"" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(12) texrAlignment:NSTextAlignmentLeft];
    }
    return _titleLabel;
}

- (BaseLabel *)valueLabel {
    if (!_valueLabel) {
        _valueLabel = [BaseLabel new];
        [_valueLabel setLabelStyle:@"" textColor:KCOLOR_heavyFont textFont:kFONT_mainFont(12) texrAlignment:NSTextAlignmentRight];
    }
    return _valueLabel;
}

- (UIView *)line {
    if (!_line) {
        _line = [UIView new];
        _line.backgroundColor = kCOLOR_line;
    }
    return _line;
}

- (BaseTextField *)inputTextfiled {
    if (!_inputTextfiled) {
        _inputTextfiled = [BaseTextField new];
        _inputTextfiled.formatType = FormatTypeNone;
        _inputTextfiled.font = kFONT_mainFont(12);
        _inputTextfiled.placeholder = @"点击输入信息";
        _inputTextfiled.textAlignment = NSTextAlignmentRight;
    }
    return _inputTextfiled;
}

- (BaseImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [BaseImageView new];
        _arrowImageView.imageName = @"dd_unity_selectArrow";
    }
    return _arrowImageView;
}

- (BaseButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [BaseButton new];
        [_selectButton setButtonStyle:@"" titleColor:KCOLOR_mainColor titleFont:kFONT_mainFont(12) texrAlignment:NSTextAlignmentRight];
        _selectButton.titleLabel.textAlignment = NSTextAlignmentRight;
        _selectButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        _selectButton.titleEdgeInsets = UIEdgeInsetsMake(0, 60, 0, 0);
    }
    return _selectButton;
}

@end
